package cn.com.ninng;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author liulekang
 * @createdate 2021/7/22
 */
public class Problem3 {

    public static void main(String[] args) {
        int abcabcbb = lengthOfLongestSubstring("abcabcdabc");
        System.out.println(abcabcbb);
    }


    public static int lengthOfLongestSubstring(String s) {

        char[] chars = s.toCharArray();
        ArrayList charList = new ArrayList();

        int result = 0;
        for (char aChar : chars) {
            if (!charList.contains(aChar)){
                charList.add(aChar);
            }else {
                result = charList.size() > result ? charList.size() : result;
                charList.subList(0, charList.indexOf(aChar) + 1).clear();
                charList.add(aChar);
            }
        }
        result = charList.size() > result ? charList.size() : result;
        return result;

    }
}
